<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class Father {
            constructor(x, y) {
                this.x = x;
                this.y = y;
            }
            sum() {
                console.log(this.x + this.y);
            }
        }

        //子类继承父类加法方法，同时 扩展减法方法
        class Son extends Father {
            constructor(x, y) {
                //调用父类中的构造方法
                //super必须在子类this之前调用
                //注意：子类在构造函数中使用super，必须放到this前面(必须先调用父类的构造方法，在使用子类的构造方法)
                super(x, y);

                this.x = x;
                this.y = y;

            }
            substract() {
                console.log((this.x - this.y));
            }
        }
        var son = new Son(5, 3)
        son.substract();
        son.sum();
    </script>
</body>

</html>